package colorChanger;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main {

	public static void main(String[] args) throws IOException {
		// http://zxing.appspot.com/generator/
		// ColoredQRCode colored = new
		// ColoredQRCode("Images/CreatedImages/pokemon.png","Images/CreatedImages/digimon.png","png");
		ColoredQRCode colored = new ColoredQRCode("Images/06102011/w3", "jpg");
		// ColoredQRCode colored = new
		// ColoredQRCode("Images/CreatedImages/coloredWhite","png");
		// ColoredQRCode colored = new
		// ColoredQRCode("Images/PureCollors/cyan2","jpg");
		// ColoredQRCode colored = new
		// ColoredQRCode("Images/BaseImages/yellow","jpg");

		// showExtremeValues("cyan");
		// showExtremeValues("magenta");
		// showExtremeValues("yellow");
		// showExtremeValues("yellow");
		// showImage(colored.getPrimaryQRCode().getImageFromPixelArray());
		// showImage(colored.getColoredQRCode().getImageFromPixelArray());
		// colored.getColoredQRCode().writhImage("coloredWhite");
		colored.getSecundaryQRCode().writhImage("w3-secundario-sim");

		colored.getPrimaryQRCode().writhImage("w3-primario-sim");
		// new Color(7676).get
		// System.out.println("white "+Color.white.getRGB());
		// System.out.println("black "+Color.black.getRGB());

	}

	private static void showExtremeValues(String color)
			throws FileNotFoundException, IOException {
		System.out.println(color);
		QRCode pureQRcode = new QRCode("Images/PureCollors/" + color + 0
				+ ".jpg");
		double greaterCyan = pureQRcode.getGreaterCyan();
		double lowerCyan = pureQRcode.getLowerCyan();
		double greaterMagenta = pureQRcode.getGreaterMagenta();
		double lowerMagenta = pureQRcode.getLowerMagenta();
		double greaterYellow = pureQRcode.getGreaterYellow();
		double lowerYellow = pureQRcode.getLowerYellow();
		double greaterKey = pureQRcode.getGreaterKey();
		double lowerKey = pureQRcode.getLowerKey();

		for (int i = 0; i < 5; i++) {
			pureQRcode = new QRCode("Images/PureCollors/" + color + i + ".jpg");
			double bigCyan = pureQRcode.getGreaterCyan();
			double bigMagenta = pureQRcode.getGreaterMagenta();
			double bigYellow = pureQRcode.getGreaterYellow();
			double bigKey = pureQRcode.getGreaterKey();
			double littleCyan = pureQRcode.getLowerCyan();
			double littleMagenta = pureQRcode.getLowerMagenta();
			double littleYellow = pureQRcode.getLowerYellow();
			double littleKey = pureQRcode.getLowerKey();

			if (bigCyan > greaterCyan) {
				greaterCyan = bigCyan;
			}
			if (littleCyan < lowerCyan) {
				lowerCyan = littleCyan;
			}
			if (bigMagenta > greaterMagenta) {
				greaterMagenta = bigMagenta;
			}
			if (littleMagenta < lowerMagenta) {
				lowerMagenta = littleMagenta;
			}
			if (bigYellow > greaterYellow) {
				greaterYellow = bigYellow;
			}
			if (littleYellow < lowerYellow) {
				lowerYellow = littleYellow;
			}
			if (bigKey > greaterKey) {
				greaterKey = bigKey;
			}
			if (bigKey < lowerKey) {
				lowerKey = bigKey;
			}
		}
		System.out.println("greater cyan " + greaterCyan);
		// System.out.println("lower cyan " + lowerCyan);
		System.out.println("greater magenta " + greaterMagenta);
		// System.out.println("lower magenta " + lowerMagenta);
		System.out.println("greater yellow " + greaterYellow);
		// System.out.println("lower yellow " + lowerYellow);
		System.out.println("greater key " + greaterKey);
		System.out.println("lower key " + lowerKey);

	}

	public static void showImage(Image image) {
		JFrame frame = new JFrame("HelloWorldSwing");
		final JLabel label = new JLabel(new ImageIcon(image));
		frame.getContentPane().add(label);
		frame.setVisible(true);

	}

	public static void showBufferedImage(BufferedImage image) {
		JFrame frame = new JFrame("HelloWorldSwing");
		final JLabel label = new JLabel(new ImageIcon(image));
		frame.getContentPane().add(label);
		frame.setVisible(true);

	}

	public static FileInputStream imageToFISs(String imagePath)
			throws IOException {
		byte[] fileBytes;
		File imageFile;
		FileInputStream fis;
		int fileLength = 0;

		imageFile = new File(imagePath);

		fis = new java.io.FileInputStream(imageFile);
		fileLength = (int) imageFile.length() + 1;
		fileBytes = new byte[fileLength];
		fis.read(fileBytes);
		fis.close();
		return fis;
	}

	public static byte[] imageToBytesArray(String imagePath) throws IOException {
		byte[] fileBytes;
		File imageFile;
		FileInputStream fis;
		int fileLength = 0;

		imageFile = new File(imagePath);

		fis = new java.io.FileInputStream(imageFile);
		fileLength = (int) imageFile.length() + 1;
		fileBytes = new byte[fileLength];
		fis.read(fileBytes);
		fis.close();
		return fileBytes;
	}

}